﻿using BCCommon;
using BCService;
using BCService.MakeStaticPagingComponent.PageTemplateSerialize.ParsePage;
using BCService.MakeStaticPagingComponent.PageTemplateSerialize.ParseTag;
using BCService.MakeStaticPagingComponent.PageTemplateSerialize.ProcessControl;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using PageTemplateSerializeConsole.Configs;
using PageTemplateSerializeConsole.Configs.Redis;
using PageTemplateSerializeConsole.Test.FackData;
using PageTemplateSerializeConsole.Test.ParseExpressionTest;
using PageTemplateSerializeConsole.Test.ParseIfCommandTest;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text.RegularExpressions;

namespace PageTemplateSerializeConsole
{
    class Program
    {
        public static IServiceCollection Services { get; }

        public static IConfiguration Configuration { get; }
        static Program()
        {
            var builder = new ConfigurationBuilder().AddJsonFile("/mnt/web/config/appsettings.production.json", optional: true, reloadOnChange: true);

#if DEBUG
            builder = new ConfigurationBuilder().AddJsonFile("appsettings.json", optional: true, reloadOnChange: true);
#endif

            Configuration = builder.Build();


            Services = new ServiceCollection()
                .AddLogging()
                .AddScoped<ILoggerFactory, LoggerFactory>()
                .AddScoped<IApplicationContextService, ConsoleContextService>()
                .AddScoped<IWebSocketContextService, WebSocketContextService>()
                .AddServices()
                .AddMapperConfiguration();

            Services.AddMySql(options =>
            {
                options.MasterConnectionString = Configuration["MySqlConnectionString"];
                options.SlaveConnectionString = Configuration["MySqlConnectionString"];
            });
            Services.AddRedis(options =>
            {
                options.RedisConnectionString = Configuration["RedisConnectionString"];
                options.RedisDatabaseNo = Configuration["RedisDatabaseNo"];
            });
            GeneralContainer.Configuration = Configuration;
            Services.AddSingleton(typeof(IConfiguration), Configuration);
            Console.WriteLine("Service Count:" + Services.Count);
            var serviceProvider = Services.BuildServiceProvider(new ServiceProviderOptions().ValidateScopes);
            var loggerFactory = serviceProvider.GetService<ILoggerFactory>().AddConsole(LogLevel.Debug);

            //全局服务提供
            GeneralContainer.ServiceProvider = serviceProvider;
        }

        static void Main(string[] args)
        {

            /*
            string command = File.ReadAllText(Path.Combine(Directory.GetCurrentDirectory(),"files", @"1.html"));

            IParsePageService parsePageService = (IParsePageService)Services.BuildServiceProvider().GetService(typeof(IParsePageService));
            string result = parsePageService.ParseCommand(command);
            Console.WriteLine(result);
            */
            Test();


            Console.ReadKey();
        }

        static void Test()
        {
            FackData fackData = new FackData();

            ParseExpressionTest parseExpressionTest = new ParseExpressionTest();
            parseExpressionTest.Test();

            ParseIfCommandTest parseIfCommandTest = new ParseIfCommandTest();
        }
    }
}
